package com.hdoit.ares.logical.official.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.hdoit.ares.logical.acc.dao.IGoldenBeanDetailDao;
import com.hdoit.ares.logical.acc.service.IAccountInfoService;
import com.hdoit.ares.logical.acc.service.IGoldenBeanDetailService;
import com.hdoit.ares.logical.acc.service.IGoldenBeanInfoService;
import com.hdoit.ares.logical.acti.service.IActiTaskService;
import com.hdoit.ares.logical.official.dao.IArticalCommentDao;
import com.hdoit.ares.logical.official.dao.IPraiseAndGlanceDao;
import com.hdoit.ares.logical.official.model.ArticalComment;
import com.hdoit.ares.logical.official.model.PraiseAndGlance;
import com.hdoit.ares.logical.official.service.IArticalCommentService;
import com.hdoit.ares.logical.viewmodel.official.ArticalCommentSearch;
import com.hdoit.ares.selfcommon.enums.official.TypeOfPraise;
import com.hdoit.ares.selfcommon.utils.EmojiUtil;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.pub.YesOrNo;
import com.tennetcn.common.logical.file.dao.IOssFileInfoDao;
import com.tennetcn.common.message.DaoBaseException;
import com.tennetcn.common.utils.CommonUtils;
import com.tennetcn.common.utils.DateUtils;
/**
 * @author      yujinhui
 * @email       
 * @createtime  2018年03月10日 14:05:47
 * @comment
 */
@Component
public class ArticalCommentServiceImpl extends SuperService<ArticalComment> implements IArticalCommentService{
	private IArticalCommentDao articalCommentDao;
	private IPraiseAndGlanceDao praiseAndGlanceDao;
	private IOssFileInfoDao fileInfoDao;
	private IGoldenBeanDetailDao goldenBeanDetailDao;
	private IAccountInfoService accountInfoService;
	private IGoldenBeanDetailService goldenBeanDetailService;
	private IGoldenBeanInfoService goldenBeanInfoService;
	private IActiTaskService actiTaskService;
	

	public IActiTaskService getActiTaskService() {
		return actiTaskService;
	}
	@Resource
	public void setActiTaskService(IActiTaskService actiTaskService) {
		this.actiTaskService = actiTaskService;
	}
	public IAccountInfoService getAccountInfoService() {
		return accountInfoService;
	}
	@Resource
	public void setAccountInfoService(IAccountInfoService accountInfoService) {
		this.accountInfoService = accountInfoService;
	}
	public IGoldenBeanDetailService getGoldenBeanDetailService() {
		return goldenBeanDetailService;
	}
	@Resource
	public void setGoldenBeanDetailService(IGoldenBeanDetailService goldenBeanDetailService) {
		this.goldenBeanDetailService = goldenBeanDetailService;
	}
	public IGoldenBeanInfoService getGoldenBeanInfoService() {
		return goldenBeanInfoService;
	}
	@Resource
	public void setGoldenBeanInfoService(IGoldenBeanInfoService goldenBeanInfoService) {
		this.goldenBeanInfoService = goldenBeanInfoService;
	}
	public IArticalCommentDao getArticalCommentDao() {
		return articalCommentDao;
	}
	@Resource
	public void setArticalCommentDao(IArticalCommentDao articalCommentDao) {
		this.articalCommentDao = articalCommentDao;
	}

    
	public IPraiseAndGlanceDao getPraiseAndGlanceDao() {
		return praiseAndGlanceDao;
	}
	@Resource
	public void setPraiseAndGlanceDao(IPraiseAndGlanceDao praiseAndGlanceDao) {
		this.praiseAndGlanceDao = praiseAndGlanceDao;
	}
	
	public IOssFileInfoDao getFileInfoDao() {
		return fileInfoDao;
	}
	@Resource
	public void setFileInfoDao(IOssFileInfoDao fileInfoDao) {
		this.fileInfoDao = fileInfoDao;
	}
	
	
	public IGoldenBeanDetailDao getGoldenBeanDetailDao() {
		return goldenBeanDetailDao;
	}
	@Resource
	public void setGoldenBeanDetailDao(IGoldenBeanDetailDao goldenBeanDetailDao) {
		this.goldenBeanDetailDao = goldenBeanDetailDao;
	}
	
	@Override
	public List<ArticalComment> queryListBySearch(ArticalCommentSearch search) {
		return articalCommentDao.queryListBySearch(search);
	}
	
	@Override
	public ArticalComment addModel(String content, String articalId,String customerId,String replyedId) {
		
		//添加评论
		ArticalComment articalComment = new ArticalComment();
		articalComment.setId(CommonUtils.getKeyId());
		articalComment.setArticalId(articalId);
		articalComment.setCustomerId(customerId);
		articalComment.setComment(content);
		articalComment.setCreateTime(DateUtils.getCurrent());
		articalComment.setDeleteMark(YesOrNo.no);
		
		if(!StringUtils.isEmpty(replyedId)){
			articalComment.setReplyedId(replyedId);
		}
		
		
				
		//添加关于评论的浏览次数和点赞次数
		PraiseAndGlance praiseAndGlance = new PraiseAndGlance();
		praiseAndGlance.setId(CommonUtils.getKeyId());
		praiseAndGlance.setType(TypeOfPraise.Comment);
		praiseAndGlance.setReceiveId(articalComment.getId());
		praiseAndGlance.setPraiseCount(0);
		praiseAndGlance.setGlanceCount(0);
		
		
		try {
			articalCommentDao.addModel(articalComment);
			praiseAndGlanceDao.addModelSelective(praiseAndGlance);
		} catch (DaoBaseException e) {
			e.printStackTrace();
		}
	

		// 任务临时注释
		/*try {
			if(articalCommentDao.addModel(articalComment)){
				// 判断是否第一次评论
				Date date = DateUtils.getCurrent();
				@SuppressWarnings("deprecation")
				String month = (date.getMonth() + 1) + "";
				@SuppressWarnings("deprecation")
				String day = (date.getDate()) + "";
				int comments = articalCommentDao.queryCountDayComments(month,day,customerId);
				System.err.println("comments***********000" + comments);
				if (comments == 1) {
					goldenBeanDetailService.addGoldenBeanDetail(TaskId.dayComment, 10, GoldenBeanType.dayComment, customerId);
				}
			}
			praiseAndGlanceDao.addModelSelective(praiseAndGlance);
		} catch (DaoBaseException e) {
			e.printStackTrace();
		}*/
			
	    ArticalCommentSearch articalCommentSearch = new ArticalCommentSearch();

	    articalCommentSearch.setId(articalComment.getId());
		articalCommentSearch.setPraiseCutomerId(customerId);
		ArticalComment comment = articalCommentDao.queryModel(articalCommentSearch);
		comment.setComment(EmojiUtil.emojiConverterUnicodeStr(comment.getComment()));
		return comment;
	}
	@Override
	public ArticalComment queryModel(ArticalCommentSearch search) {
		return articalCommentDao.queryModel(search);
	}
	
	@Override
	public int queryCountDayComments(String month, String day, String customerId) {
		return articalCommentDao.queryCountDayComments(month, day, customerId);
	}
	@Override
	public boolean queryCountDayComment(String month, String day, String customerId) {
		if(articalCommentDao.queryCountDayComments(month, day,customerId)>=1){
			return true;
		}
		return false;
	}

}
